<div class="post-title"><h2><a href="<?php echo current_url();?>"><?php echo $title; ?></a></h2></div>

<div class="post-body">

<?php
	echo form_open('aset/'.$form_act, 'id="aset_form"');

	echo "<div id='error' class='error-message' ";

	if($this->session->userdata('ERRMSG_ARR'))
	{
		echo ">";
		echo $this->session->userdata('ERRMSG_ARR');
		$this->session->unset_userdata('ERRMSG_ARR');
	}
	else
	{
		echo "style='display:none'>";
	}
	
	echo "</div>";

	$data['class'] = 'input';
	if ($act == 'view') $data['disabled'] = TRUE;
?>
	
	<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">						  
		<tr>
			<th><?php echo form_label('Kode *','id_aset'); ?></th>
			<td>
				
				<?php 
					$data['name'] = $data['id'] = 'id_aset';
					if($act=='add')
					{ 
						if($new_id == ''){						
							$data['value'] = 'A001';
						}else{						
							$data['value'] = 'A' . formatIdaset(substr($new_id->id_aset, 1) + 1);
						}
					}else{
						$data['value'] = (set_value('id_aset')) ? set_value('id_aset') : $aset_data['id_aset'];
					}					
					$data['title'] = "ID tidak boleh kosong";
					echo form_input($data);
				?>
			</td>
		</tr>							
		<tr>
			<th><?php echo form_label('Nama Aset *','nama_aset'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'nama_aset';
					$data['value'] = (set_value('nama_aset')) ? set_value('nama_aset') : $aset_data['nama_aset'];
					$data['title'] = "Nama tidak boleh kosong";						
					echo form_input($data);
				?>
			</td>
		</tr>
		<tr>
			<th><?php echo form_label('Tanggal Pembelian* (YYYY-mm-dd)','tgl_beli'); ?></th>
			<td>
				<?php 
					$data['name'] = 'tgl_beli';
					$data['id'] = 'datepicker2';
					$data['value'] = (set_value('tgl_beli')) ? set_value('tgl_beli') : $aset_data['tgl_beli'];
					$data['title'] = "Tanggal lahir harus diisi dengan format dddd-mm-yy";				
					echo form_input($data);
				?>
			</td>				
		</tr>
		<tr>
			<th><?php echo form_label('Harga Beli *','harga_beli'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'harga_beli';
					$data['value'] = (set_value('harga_beli')) ? set_value('harga_beli') : $aset_data['harga_beli'];
					$data['title'] = "Harga Beli tidak boleh kosong";						
					echo form_input($data);
				?>
			</td>
		</tr>	
		<tr>
			<th><?php echo form_label('Nilai Residu','nilai_residu'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'nilai_residu';
					$data['value'] = (set_value('nilai_residu')) ? set_value('nilai_residu') : $aset_data['nilai_residu'];
					$data['title'] = "Nilai Residu tidak boleh kosong";						
					echo form_input($data);
				?>
			</td>
		</tr>	
		<tr>
			<th><?php echo form_label('Nilai Buku ','nilai_buku'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'nilai_buku';
					$data['value'] = (set_value('nilai_buku')) ? set_value('nilai_buku') : $aset_data['nilai_buku'];
					$data['title'] = "Nilai Buku tidak boleh kosong";
					echo form_input($data);
				?>
			</td>
		</tr>		
		
		<tr>
			<th><?php echo form_label('Tanggal Perhitungan* (YYYY-mm-dd)','tgl_hitung'); ?></th>
			<td>
				<?php 
					$data['name'] = 'tgl_hitung';
					$data['id'] = 'datepicker3';
					$data['value'] = (set_value('tgl_hitung')) ? set_value('tgl_hitung') : $aset_data['tgl_hitung'];
					$data['title'] = "Tanggal Masuk harus diisi dengan format dddd-mm-yy";				
					echo form_input($data);
				?>
			</td>				
		</tr>
		</tr>					
		<tr>
			<th>
				<?php echo form_label('Keterangan','keterangan'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'keterangan';
					$data['value'] = (set_value('keterangan')) ? set_value('keterangan') : $aset_data['keterangan'];
					echo form_textarea($data);
				?>													
			</td>
		</tr>																																										
	</table>
	
	<div class="buttons">
		<?php 
			if($act!='view')
			{ 
				echo form_submit('simpan','Simpan', "id = 'button-save'" );
				echo form_reset('reset','Reset', "id = 'button-reset'" );
				echo form_button(array('id' => 'button-cancel', 'content' => 'Batal', 'onClick' => "location.href='".site_url()."aset'" ));
			}
			else
			{
				echo form_button(array('id' => 'button-cancel', 'content' => 'Kembali', 'onClick' => "location.href='".site_url()."aset'" ));
			}
		?>				
	</div>

<?php echo form_close(); ?>

</div>	

<script type='text/javascript'>
	//Validasi di client
	$(document).ready(function()
	{
		$('#aset_form').validate({
			errorLabelContainer: "#error",
			wrapper: "li",
			rules: 
			{
				id_aset: "required",				
				nama_aset: "required",
				harga_beli: "required",
				tgl_beli: "dateISO",
				tgl_hitung: "dateISO",
				nilai_buku: "required"
			}
		});
	});
</script>

<?php
	function formatIdaset($id){		
		if (strlen($id) == 1)
		{
			return '00' . $id;
		}
		else if (strlen($id) == 2)
		{
			return '0' . $id;
		}
		else {
			return $id;
		}
	}
?>